package com.zdkj.subway.check.controller.stationTiecketManager.xianWngCJXXQR.shouRuJS;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zdkj.admin.api.entity.SysUser;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.constant.SecurityConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.check.annotation.SwCheckNoRepeatSubmitBaseController;
import com.zdkj.subway.check.entity.*;
import com.zdkj.subway.check.enums.ResultDetailMsg;
import com.zdkj.subway.check.fegin.SubwayStmService;
import com.zdkj.subway.check.mapper.*;
import com.zdkj.subway.check.result.Result;
import com.zdkj.subway.check.util.*;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 线网下的BOM收入结算
 */
@RequestMapping("/xw_js_bom")
@RestController
@Slf4j
public class Xw_BOM_shouJieSuanCtrl extends SwCheckNoRepeatSubmitBaseController {

    @Resource
    XwShouJieSuanMapper xwShouJieSuanMapper;
    @Resource
    SwAuTvmBoxAmountDifferenceMapper swAuTvmBoxAmountDifferenceMapper;
    @Resource
    SwStMarketingTicketMapper swStMarketingTicketMapper;
    @Resource
    SwStMarketingTicketGroupSellMapper swStMarketingTicketGroupSellMapper;
    @Resource
    SwStMarketingTicketOffineSellMapper swStMarketingTicketOffineSellMapper;
    @Resource
    SwStMarketingTicketOffineTakeTicketMapper swStMarketingTicketOffineTakeTicketMapper;
    @Resource
    SwStBomIncomeSettleMapper swStBomIncomeSettleMapper;
    @Resource
    SysUserMapper sysUserMapper;
    @Resource
    SwStLongperiodSettleLogMapper swStLongperiodSettleLogMapper;
    @Resource
    SwAuCenterConductorAmountDifferenceMapper swAuCenterConductorAmountDifferenceMapper;
    @Resource
    SwStConductorSettleRepairMapper swStConductorSettleRepairMapper;
    @Resource
    SwStReportErrorAlterAppayMapper swStReportErrorAlterAppayMapper;
    @Autowired
    private SwStInputPassengerWorkMapper swStInputPassengerWorkMapper;
    @Autowired
    private SwStInputPassengerWorkOtherMapper swStInputPassengerWorkOtherMapper;
    @Autowired
    private SwStInputPassengerWorkTicketMapper swStInputPassengerWorkTicketMapper;
    @Resource
    private SwStTicketPettyAddMapper swStTicketPettyAddMapper;
    @Autowired
    private SubwayStmService subwayStmService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    /**
     * bom待提交主页
     * @param page
     * @param param
     * @return
     */
    @RequestMapping("/getXw_bom_shouJieSuan_waitSubmit")
    @ApiOperation(value = "bom待提交主页", notes = "bom待提交主页")
    public Page getXw_tvm_shouJieSuan_waitSubmit(Page page,@RequestParam Map<String,String> param) throws ParseException, SQLException {
        param.put("isAddReportError","0");
        List<Map<String,Object>> tvm_shouJieSuan_waitSubmit=BomUtil.getXw_bom_shouJieSuan_waitSubmit(param);
        List<Integer> smtIdList = new ArrayList<>();
        for(Map<String,Object> map:tvm_shouJieSuan_waitSubmit){
            Integer smtId = (Integer)map.get("smtId");
            smtIdList.add(smtId);
        }
        if(CollectionUtil.isNotEmpty(smtIdList)){
            Map<String, BigDecimal> electronicAmountMap = new HashMap<>();
            //团购的非现金
            QueryWrapper<SwStMarketingTicketGroupSell> swStMarketingTicketGroupSellQueryWrapper=new QueryWrapper<>();
            swStMarketingTicketGroupSellQueryWrapper.select("ifnull(sum(discount_amount),0) discount_amount,relation_id");
            swStMarketingTicketGroupSellQueryWrapper.eq("del_flag",0);
            String[] pay_method={"1","2","3"}; //微信，现金，银行
            swStMarketingTicketGroupSellQueryWrapper.in("pay_method",pay_method);
            swStMarketingTicketGroupSellQueryWrapper.in("relation_id",smtIdList);
            swStMarketingTicketGroupSellQueryWrapper.groupBy("relation_id");
            List<SwStMarketingTicketGroupSell> swStMarketingTicketGroupSells = swStMarketingTicketGroupSellMapper.selectList(swStMarketingTicketGroupSellQueryWrapper);
            if(CollectionUtil.isNotEmpty(swStMarketingTicketGroupSells)){
                for (SwStMarketingTicketGroupSell swStMarketingTicketGroupSell : swStMarketingTicketGroupSells) {
                    Integer relationId = swStMarketingTicketGroupSell.getRelationId();
                    BigDecimal discountAmount = swStMarketingTicketGroupSell.getDiscountAmount();
                    electronicAmountMap.put(String.valueOf(relationId),discountAmount);
                }
            }

            //线下取票明细
            QueryWrapper<SwStMarketingTicketOffineTakeTicket> swStMarketingTicketOffineTakeTicketQueryWrapper=new QueryWrapper<>();
            swStMarketingTicketOffineTakeTicketQueryWrapper.select("ifnull(sum(sell_amount),0) sell_amount,relation_id");
            swStMarketingTicketOffineTakeTicketQueryWrapper.in("relation_id",smtIdList);
            swStMarketingTicketOffineTakeTicketQueryWrapper.eq("del_flag",0);
            swStMarketingTicketOffineTakeTicketQueryWrapper.groupBy("relation_id");
            List<SwStMarketingTicketOffineTakeTicket> swStMarketingTicketOffineTakeTickets = swStMarketingTicketOffineTakeTicketMapper.selectList(swStMarketingTicketOffineTakeTicketQueryWrapper);
            if(CollectionUtil.isNotEmpty(swStMarketingTicketOffineTakeTickets)){
                for (SwStMarketingTicketOffineTakeTicket swStMarketingTicketOffineTakeTicket : swStMarketingTicketOffineTakeTickets) {
                    Integer relationId = swStMarketingTicketOffineTakeTicket.getRelationId();
                    BigDecimal sellAmount = swStMarketingTicketOffineTakeTicket.getSellAmount();
					//log.info("0630测试sellAmount----------------"+sellAmount);
                    //校验
                    BigDecimal decimal = ifnull(electronicAmountMap, String.valueOf(relationId));
					//log.info("0630测试decimal----------------"+decimal);
					if(decimal!=null){
					   BigDecimal add = decimal.add(sellAmount);
					   //log.info("0630测试add----------------"+add);
                       electronicAmountMap.put(String.valueOf(relationId),add);
					}else{
					   electronicAmountMap.put(String.valueOf(relationId),sellAmount);  
					}
                   
					//log.info("0630测试add over----------------");
                }
            }
            for (Map<String, Object> map : tvm_shouJieSuan_waitSubmit) {
                Object smtId = map.get("smtId");
                if(smtId != null){
                    String relationId = String.valueOf(smtId);
                    //校验
                    BigDecimal decimal = ifnull(electronicAmountMap, relationId);
                    map.put("electronicAmount",decimal);
                }else {
                    map.put("electronicAmount",new BigDecimal("0"));
                }
            }
        }
        //for(Map<String,Object> map:tvm_shouJieSuan_waitSubmit){
        //    Object smtId = map.get("smtId");
        //    BigDecimal electronicAmount=new BigDecimal(0);//电子金额
        //
		//	//团购的非现金
        //    QueryWrapper<SwStMarketingTicketGroupSell> swStMarketingTicketGroupSellQueryWrapper=new QueryWrapper<>();
        //    swStMarketingTicketGroupSellQueryWrapper.select("ifnull(sum(discount_amount),0) discount_amount");
        //    swStMarketingTicketGroupSellQueryWrapper.eq("relation_id",smtId);
        //    swStMarketingTicketGroupSellQueryWrapper.eq("del_flag",0);
        //    String[] pay_method={"1","2","3"}; //微信，现金，银行
        //    swStMarketingTicketGroupSellQueryWrapper.in("pay_method",pay_method);
        //    log.info("待提交begin：循环01"+ LocalDateTime.now());
        //    List<Map<String, Object>> maps = swStMarketingTicketGroupSellMapper.selectMaps(swStMarketingTicketGroupSellQueryWrapper);
        //    log.info("待提交end：循环01"+ LocalDateTime.now());
        //    if(maps!=null && maps.size()>0){
        //        Map<String, Object> res = maps.get(0);
        //        BigDecimal discount_amount = (BigDecimal)res.get("discount_amount");
        //        electronicAmount=electronicAmount.add(discount_amount);
        //    }
        //
		//	//线下取票明细
        //
        //    QueryWrapper<SwStMarketingTicketOffineTakeTicket> swStMarketingTicketOffineTakeTicketQueryWrapper=new QueryWrapper<>();
        //    swStMarketingTicketOffineTakeTicketQueryWrapper.select("ifnull(sum(sell_amount),0) sell_amount");
        //    swStMarketingTicketOffineTakeTicketQueryWrapper.eq("relation_id",smtId);
        //    swStMarketingTicketOffineTakeTicketQueryWrapper.eq("del_flag",0);
        //    BigDecimal sell=new BigDecimal(0);
        //    log.info("待提交begin：循环02"+ LocalDateTime.now());
        //    List<Map<String, Object>> map3 = swStMarketingTicketOffineTakeTicketMapper.selectMaps(swStMarketingTicketOffineTakeTicketQueryWrapper);
        //    log.info("待提交end：循环02"+ LocalDateTime.now());
        //    if(map3!=null && map3.size()>0){
        //        Map<String, Object> res = map3.get(0);
        //        BigDecimal sell_amount = (BigDecimal)res.get("sell_amount");
        //        sell=sell.add(sell_amount);
        //    }
        //
        //    electronicAmount=electronicAmount.add(sell);
        //    map.put("electronicAmount",electronicAmount);
        //}
        page.setData(tvm_shouJieSuan_waitSubmit);
        return page;
    }

    private BigDecimal ifnull(Map<String, BigDecimal> electronicAmountMap, String relationId) {
        if (electronicAmountMap == null || electronicAmountMap.size() == 0){
            return new BigDecimal("0");
        }
        try {
            BigDecimal decimal = electronicAmountMap.get(relationId);
            return decimal;
        }catch (Exception e){

        }
        return new BigDecimal("0");
    }

    /**
     * 收入结算bom补提交
     * @param page
     * @param param
     * @return
     */
    @RequestMapping("/getXw_bom_shouJieSuan_for_waitSubmit")
    @ApiOperation(value = "收入结算bom补提交", notes = "收入结算bom补提交")
    public R getXw_bom_shouJieSuan_for_waitSubmit(com.baomidou.mybatisplus.extension.plugins.pagination.Page page,@RequestParam Map<String,Object> param) throws SQLException {
        PigxUser user = SecurityUtils.getUser();
        if(user.getBelongToLine()){
            List lineList = LineOrStation.getmanagementLine();
            param.put("lines",lineList);
        }else{
            List lineList = LineOrStation.getLineOrManagementLine();
            param.put("lines",lineList);
        }
        //收入结算补提交
        IPage<SwStConductorSettle> shouJieSuan_ = swStConductorSettleRepairMapper.getXw_bom_shouJieSuan_for_waitSubmit(page,param);
        /*String sqlSettle =  BomUtil.sqlSettle(null,null);
        List<Map<String, Object>> mapsSettle = JdbcUtil.exeSqlQuery(sqlSettle);
        List<Integer> lstIds = new ArrayList();
        if(CollectionUtil.isNotEmpty(mapsSettle) && mapsSettle.size()>0){
            for(int i=0;i<mapsSettle.size();i++){
                Map<String,Object> map = mapsSettle.get(i);
                lstIds.add(Integer.valueOf(String.valueOf(map.get("id"))));
            }
        }*/
        Iterator<SwStConductorSettle> map = shouJieSuan_.getRecords().iterator();
        while (map.hasNext()){
            SwStConductorSettle next = map.next();
            /*boolean flag = false;
            if(CollectionUtil.isNotEmpty(lstIds)) {
                Object id = next.getId();
                if(lstIds.contains(id)){
                    map.remove();
                    flag = true;
                }
            }
            if(!flag) {*/
                //计算电子金额
                findEleAmount(next);
            //}
        }
        return R.ok(shouJieSuan_);
    }

    /**
     * 计算电子金额
     * @param next
     * @return
     */
    private BigDecimal findEleAmount(SwStConductorSettle next) {
        BigDecimal electronicAmount = new BigDecimal(0);//电子金额
        LambdaQueryWrapper<SwStMarketingTicket> queryWrapperMarketingTicket = new LambdaQueryWrapper<>();
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getLineCode,next.getLineCode());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getStationCode,next.getStationCode());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getDeviceOperateNum,next.getDeviceOperateNum());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getBomCode,next.getBomCode());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getConductorJobNo,next.getConductorJobNo());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getOpertorTime,next.getSettleTime());
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getConductorShifts,next.getConductorShifts());
		queryWrapperMarketingTicket.eq(SwStMarketingTicket::getConfirmStatus,"1");
        queryWrapperMarketingTicket.eq(SwStMarketingTicket::getDelFlag, "0");
        List<SwStMarketingTicket> marketingTicketMaps = swStMarketingTicketMapper.selectList(queryWrapperMarketingTicket);
        next.setElectronicAmount(new BigDecimal("0.00"));
        if(marketingTicketMaps!=null && marketingTicketMaps.size()>0) {
            SwStMarketingTicket swStMarketingTicket = marketingTicketMaps.get(0);
            Long smtId = swStMarketingTicket.getId();
            if (smtId != null) {
                //团购的非现金
                QueryWrapper<SwStMarketingTicketGroupSell> swStMarketingTicketGroupSellQueryWrapper = new QueryWrapper<>();
                swStMarketingTicketGroupSellQueryWrapper.select("ifnull(sum(discount_amount),0) discount_amount");
                swStMarketingTicketGroupSellQueryWrapper.eq("relation_id", smtId);
                swStMarketingTicketGroupSellQueryWrapper.eq("del_flag", 0);
                String[] pay_method = {"1", "2", "3"}; //微信，现金，银行
                swStMarketingTicketGroupSellQueryWrapper.in("pay_method", Arrays.asList(pay_method));
                List<Map<String, Object>> maps = swStMarketingTicketGroupSellMapper.selectMaps(swStMarketingTicketGroupSellQueryWrapper);
                if (maps != null && maps.size() > 0) {
                    Map<String, Object> res = maps.get(0);
                    BigDecimal discount_amount = (BigDecimal) res.get("discount_amount");
                    electronicAmount = electronicAmount.add(discount_amount);
                }
                //线下取票明细
                QueryWrapper<SwStMarketingTicketOffineTakeTicket> swStMarketingTicketOffineTakeTicketQueryWrapper = new QueryWrapper<>();
                swStMarketingTicketOffineTakeTicketQueryWrapper.select("ifnull(sum(sell_amount),0) sell_amount");
                swStMarketingTicketOffineTakeTicketQueryWrapper.eq("relation_id", smtId);
                swStMarketingTicketOffineTakeTicketQueryWrapper.eq("del_flag", 0);
                BigDecimal sell = new BigDecimal(0);
                List<Map<String, Object>> map3 = swStMarketingTicketOffineTakeTicketMapper.selectMaps(swStMarketingTicketOffineTakeTicketQueryWrapper);//
                if (map3 != null && map3.size() > 0) {
                    Map<String, Object> res = map3.get(0);
                    BigDecimal sell_amount = (BigDecimal) res.get("sell_amount");
                    sell = sell.add(sell_amount);
                }
                electronicAmount = electronicAmount.add(sell);
                next.setElectronicAmount(electronicAmount);
            }
        }
        return electronicAmount;
    }

    /**
     * BOM补提交
     * @param json
     * @return
     * @throws ParseException
     */
    @RequestMapping("/bomForSubmit")
    @ApiOperation(value = "BOM补提交", notes = "BOM补提交")
    @Transactional(rollbackFor = Exception.class)
    public Result bomForSubmit(@RequestBody JSONObject json) {
        String params=json.getString("params");
        String attendancePersonJobNo= SecurityUtils.getUser().getUserCode();
        Result res=new Result(ResultDetailMsg.OK);
        String md5 = MD5.create().digestHex(params);
        //防止重复提交
        if (noPass(SecurityUtils.getUser().getId(), "bomSubmit", md5)) {
            res.setMsg("请勿重复提交");
            return res;
        }
        JSONArray jsonArray = JSONArray.parseArray(params);
        try {
            for(int i=0;i<jsonArray.size();i++){
                JSONObject param = jsonArray.getJSONObject(i);
                Integer id = param.getInteger("id");
                //查未提交的数据
                SwStConductorSettle conductorSettle = null;
                SwStConductorSettle settle = swStConductorSettleRepairMapper.selectById(id);
                if(ObjectUtil.isNotEmpty(settle)){
                    //补提交合并处理
                    List<SwStConductorSettle> merge = findMerge(settle);
                    //重新组织数据
                    if(CollectionUtil.isNotEmpty(merge)){
                        //TODO 调用车站合并方法 原来已经提交的结算单ID和待提交的售票员结算单合并
                        List<Integer> ids = new ArrayList<>();
                        ids.add(merge.get(0).getId());
                        ids.add(settle.getId());

                        String paramStar = JSONObject.toJSONString(param);
                        //合并数据  对两条数据进行合并  审核补提交合并调用
                        R<Map<String,String>> mapR = subwayStmService.submissionMerge(settle, paramStar, ids, merge.get(0).getConductorShifts(), true, true, SecurityConstants.FROM);
                        int rCode = mapR.getCode();
                        if(1 == rCode) {
                            throw new RuntimeException("fegin调用异常！");
                        }
                        Map<String, String> data = mapR.getData();
                        if(data != null && !data.isEmpty()){
                            conductorSettle = JSONObject.parseObject(data.get("merge"), SwStConductorSettle.class);
                            conductorSettle.setElectronicAmount(merge.get(0).getElectronicAmount());

                            param = (JSONObject) JSONObject.toJSON(conductorSettle);
                            param.put("marketTicketAmount",new BigDecimal(data.get("marketTicketAmount")));
                            param.put("passengerWorkAmount",new BigDecimal(data.get("passengerWorkAmount")));
                            param.put("singleTicketAmount",new BigDecimal(data.get("singleTicketAmount")));
							param.put("emergencyAmount",new BigDecimal(data.get("emergencyAmount")));
                            param.put("haveBus",Integer.valueOf(data.get("haveBus")));
							param.put("haveMarket",Integer.valueOf(data.get("haveMarket")));
                            param.put("isflag","标识");
                        }
                    }

                    Date startTimeD=DateFormat.LocalDateToUdate(settle.getSettleTime());
                    Date endTimeD=DateFormat.LocalDateToUdate(settle.getSettleTime());
                    //利用Calendar 实现 Date日期+1天
                    Calendar c = Calendar.getInstance();
                    c.setTime(endTimeD);
                    c.add(Calendar.DAY_OF_MONTH, 1);
                    endTimeD = c.getTime();
                    String startTime=DateFormat.date_ex_str(startTimeD,"yyyy-MM-dd")+" 02:00:00";
                    String endTime=DateFormat.date_ex_str(endTimeD,"yyyy-MM-dd")+" 01:59:59";
                    param.put("startTime",startTime);
                    param.put("endTime",endTime);
                    SimpleDateFormat sm2 = new SimpleDateFormat("yyyy-MM-dd");
                    Date settleTime = sm2.parse(param.getString("settleTime"));
                    SwStBomIncomeSettle swStBomIncomeSettle = new SwStBomIncomeSettle();
                    swStBomIncomeSettle.setLineCode(param.getString("lineCode"));
                    swStBomIncomeSettle.setStationCode(param.getString("stationCode"));
                    swStBomIncomeSettle.setBomCode(param.getString("bomCode"));
                    swStBomIncomeSettle.setConductorJobNo(param.getString("conductorJobNo"));
                    swStBomIncomeSettle.setDeviceOperatorNum(param.getString("deviceOperateNum"));
                    swStBomIncomeSettle.setRecordTime(settleTime);
                    swStBomIncomeSettle.setConductorShifts(param.getString("conductorShifts"));//班次
                    swStBomIncomeSettle.setDelFlag("0");
                    QueryWrapper<SwStBomIncomeSettle> queryWrapperSwStBomIncomeSettle=new QueryWrapper<>();
                    queryWrapperSwStBomIncomeSettle.setEntity(swStBomIncomeSettle);
                    List<SwStBomIncomeSettle> swStBomIncomeSettles = swStBomIncomeSettleMapper.selectList(queryWrapperSwStBomIncomeSettle);
                    if(swStBomIncomeSettles.size()>0){
                        swStBomIncomeSettle=swStBomIncomeSettles.get(0);
                    }
                    QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
                    queryWrapper.select("ifnull(group_concat(user_id),'') user_id");
                    String conductorJobNo = (String)param.get("conductorJobNo");
                    if(conductorJobNo!=null && conductorJobNo!=""){
                        queryWrapper.in("user_code",conductorJobNo.split(","));
                    }
                    List<Map<String, Object>> sysUsers = sysUserMapper.selectMaps(queryWrapper);
                    String ConductorIds = (String) sysUsers.get(0).get("user_id");
                    swStBomIncomeSettle.setConductorId(ConductorIds);
                    Date workingStartTime = DateFormat.stringToDateFormat(param.getString("startTime"));
                    swStBomIncomeSettle.setSettleStartTime(workingStartTime);
                    Date workingEndTime =  DateFormat.stringToDateFormat(param.getString("endTime"));
                    swStBomIncomeSettle.setSettleEndTime(DateFormat.date_add_or_sub_days(workingEndTime,-1));
                    Date curr_date = new Date();
                    String startdateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 00:00:00";
                    String middledateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 01:59:59";
                    //String enddateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 23:59:59";
                    Date startdate=DateFormat.panDuanDate(startdateStr);
                    Date middledate=DateFormat.panDuanDate(middledateStr);
                    //Date enddate=DateFormat.panDuanDate(enddateStr);
                    Date enddate = DateFormat.date_add_or_sub_days(startdate, 1);//避免1秒误差，改为 加一天
                    if(curr_date.compareTo(startdate)>=0 && curr_date.compareTo(middledate)<=0){
                        curr_date=DateFormat.date_add_or_sub_days(curr_date,-1);//前推一天
                        swStBomIncomeSettle.setSettleTime(curr_date);
                    }else if(curr_date.compareTo(middledate)>0 && curr_date.compareTo(enddate)<0){
                        swStBomIncomeSettle.setSettleTime(curr_date);
                    }
                    swStBomIncomeSettle.setCashReceiptAmount(new BigDecimal(param.getString("realAmount")));
                    swStBomIncomeSettle.setAdvanceAmount(new BigDecimal(param.getString("adanceAmount")));
                    swStBomIncomeSettle.setElectronicAmount(new BigDecimal(param.getString("electronicAmount")));
                    swStBomIncomeSettle.setPassengerAttendantId(1);
                    swStBomIncomeSettle.setPassengerAttendantJobNo(String.valueOf(param.getString("passengerAttendantJobNo")));
                    swStBomIncomeSettle.setPassengerAttendantName(String.valueOf(param.getString("passengerAttendantName")));
                    Map<String, Object> p = new HashMap<>();
                    p.put("user_code", attendancePersonJobNo);
                    swStBomIncomeSettle.setAttendancePersonId(SecurityUtils.getUser().getId());
                    swStBomIncomeSettle.setAttendancePersonJobNo(attendancePersonJobNo);
                    swStBomIncomeSettle.setAttendancePersonName(SecurityUtils.getUser().getNikeName());
                    long l = (workingEndTime.getTime() - workingStartTime.getTime()) / (24 * 60 * 60 * 1000);
                    swStBomIncomeSettle.setSettleDays(Integer.parseInt(String.valueOf(l)));
                    swStBomIncomeSettle.setDeptId(UserInfo.getDeptId());
                    swStBomIncomeSettle.setCreatorId(UserInfo.getId());
                    swStBomIncomeSettle.setCreatorName(UserInfo.getName());
                    swStBomIncomeSettle.setCreateTime(new Date());
                    swStBomIncomeSettle.setUpdateTime(new Date());
                    swStBomIncomeSettle.setSettleStatus("1");
                    swStBomIncomeSettle.setIsAddReportError("0");
                    swStBomIncomeSettle.setDelFlag("0");
                    swStBomIncomeSettle.setAdditionalRecordingStatus("1");
                    if(swStBomIncomeSettles.size()>0){
                        swStBomIncomeSettleMapper.updateById(swStBomIncomeSettle);
                    }else{
                        Integer ref = swStBomIncomeSettleMapper.insertSwStBomIncomeSettle(swStBomIncomeSettle);
                    }
                    //修改提交状态和报表修改状态
                    updateStatusSubmitStatus(param);
                    //修改报表差错更改申请状态
                    updateReportDatas(param);
                    //添加到售票员票款差异审核表
                    if(conductorSettle != null){
                        repairSwAuCenterConductorAmountDifference(param,conductorSettle,swStBomIncomeSettle.getId());
                    }else {
                        repairSwAuCenterConductorAmountDifference(param,settle,swStBomIncomeSettle.getId());
                    }
                }
            }
        }catch (Exception e){
            log.error("提交失败",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.setMsg("提交失败");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return res;
    }

    /**
     * 补提交合并数据处理
     * @param settle
     */
    public List<SwStConductorSettle> findMerge(SwStConductorSettle settle) {
        //电子金额
        BigDecimal electronicAmount = findEleAmount(settle);
        // 根据 线路+站点+售票员工号+售票员设备操作号+收益日期+已提交  查询已提交并且是否有需要合并的
        List<SwStConductorSettle> isMergeConductorSettle = swStConductorSettleRepairMapper.selectList(Wrappers.<SwStConductorSettle>lambdaQuery()
                .eq(SwStConductorSettle::getLineCode, settle.getLineCode())
                .eq(SwStConductorSettle::getStationCode, settle.getStationCode())
                .eq(SwStConductorSettle::getDeviceOperateNum, settle.getDeviceOperateNum())
                .eq(SwStConductorSettle::getSettleTime, settle.getSettleTime())
                .eq(SwStConductorSettle::getApprovalStatus, CommonConstants.SUBMIT)
                .eq(SwStConductorSettle::getDelFlag, "0")
        );
        //不是null  就根据 线路+站点+售票员工号+售票员设备操作号+收益日期  在该表 sw_au_center_conductor_amount_difference 是否存在 查已提交的
        if(CollectionUtil.isNotEmpty(isMergeConductorSettle)){
            //要合并的电子金额累加
            electronicAmount = electronicAmount.add(findEleAmount(isMergeConductorSettle.get(0)));
            isMergeConductorSettle.get(0).setElectronicAmount(electronicAmount);

            List<SwAuCenterConductorAmountDifference> amountDifferenceSubmitted = swAuCenterConductorAmountDifferenceMapper.selectList(Wrappers.<SwAuCenterConductorAmountDifference>lambdaQuery()
                    .eq(SwAuCenterConductorAmountDifference::getLineCode, isMergeConductorSettle.get(0).getLineCode())
                    .eq(SwAuCenterConductorAmountDifference::getStationCode, isMergeConductorSettle.get(0).getStationCode())
                    .eq(SwAuCenterConductorAmountDifference::getEquipmentNumber, isMergeConductorSettle.get(0).getDeviceOperateNum())
                    .eq(SwAuCenterConductorAmountDifference::getIsMergeRecord, "0")
                    .eq(SwAuCenterConductorAmountDifference::getRecordTime, isMergeConductorSettle.get(0).getSettleTime())
                    .eq(SwAuCenterConductorAmountDifference::getDelFlag, "0")
            );
            if(CollectionUtil.isNotEmpty(amountDifferenceSubmitted)){
                int iAuConductorId = 0;//收入审核表原来已提交的ID sw_au_center_conductor_amount_difference
                int iHaveSumbitConductorId=0;//已提交过的售票员结算ID sw_st_conductor_settle
                int iToSubmitConductorId =0;//待提交的售票员结算单ID sw_st_conductor_settle
                int iBomIncomeId = 0;//BOM收入结算表ID sw_st_bom_income_settle
                int iBomLogId = 0;//日志跟踪表ID sw_st_longperiod_settle_log

                List<Integer> idsDif = amountDifferenceSubmitted.stream().map(SwAuCenterConductorAmountDifference::getId).collect(Collectors.toList());
                List<Integer> inIdsDif = amountDifferenceSubmitted.stream().map(SwAuCenterConductorAmountDifference::getIncomeSettleId).collect(Collectors.toList());
                //删除已提交收入审核主表数据
                swAuCenterConductorAmountDifferenceMapper.deleteBatchIds(idsDif);
                ////删除已提交BOM收入结算表数据
                swStBomIncomeSettleMapper.deleteBatchIds(inIdsDif);
                //查已提交日志跟踪表
                List<SwStLongperiodSettleLog> longperiodSettleLogsSubmitted = swStLongperiodSettleLogMapper.selectList(Wrappers.<SwStLongperiodSettleLog>lambdaQuery()
                        .eq(SwStLongperiodSettleLog::getLineCode, amountDifferenceSubmitted.get(0).getLineCode())
                        .eq(SwStLongperiodSettleLog::getStationCode, amountDifferenceSubmitted.get(0).getStationCode())
                        .eq(SwStLongperiodSettleLog::getConductorJobNo, amountDifferenceSubmitted.get(0).getConductorJobNo())
                        .eq(SwStLongperiodSettleLog::getDeviceNo, amountDifferenceSubmitted.get(0).getBomCode())
                        .eq(SwStLongperiodSettleLog::getDeviceType, "2")
                );
                //删除已提交日志跟踪表数据
                if(CollectionUtil.isNotEmpty(longperiodSettleLogsSubmitted)){
                    List<Integer> ids = longperiodSettleLogsSubmitted.stream().map(SwStLongperiodSettleLog::getId).collect(Collectors.toList());
                    swStLongperiodSettleLogMapper.deleteBatchIds(ids);
                }

//                //TODO 调用车站合并方法 原来已经提交的结算单ID和待提交的售票员结算单合并
////                List<Integer> ids = new ArrayList<>();
////                ids.add(isMergeConductorSettle.get(0).getId());
////                ids.add(settle.getId());
////                R<Map<String,String>> mapR = subwayStmService.submissionMerge(settle, ids, isMergeConductorSettle.get(0).getConductorShifts(), true, SecurityConstants.FROM);
////                Map<String, String> data = mapR.getData();
////                if(data != null && !data.isEmpty()){
////                    //重新组织数据
////                    //param = (JSONObject) JSONObject.toJSON(data);
////                    //param.put("electronicAmount",electronicAmount);
////                    conductorSettle.setElectronicAmount(electronicAmount);
////                    return conductorSettle;
////                }
                return isMergeConductorSettle;
            }
        }
        return null;
    }

    /**
     * 添加到售票员票款差异审核表
     * @param param
     * @param settle
     * @param settleId
     * @return
     * @throws ParseException
     * @throws SQLException
     * @throws IllegalAccessException
     */
    public boolean repairSwAuCenterConductorAmountDifference(JSONObject param,SwStConductorSettle settle,Integer settleId) throws ParseException, SQLException, IllegalAccessException {
        PigxUser user = SecurityUtils.getUser();
        Date settleStartTime = DateFormat.stringToDateFormat(param.getString("startTime"));
        Date settleEndTime = DateFormat.stringToDateFormat(param.getString("endTime"));
        SwAuCenterConductorAmountDifference swAuCenterConductorAmountDifference=new SwAuCenterConductorAmountDifference();
        Map<String, BigDecimal> scLcAcc = BomUtil.getScLcAccRepair(param);
        swAuCenterConductorAmountDifference.setLineCode(param.getString("lineCode"));
        swAuCenterConductorAmountDifference.setStationCode(param.getString("stationCode"));
        SimpleDateFormat settle_time_sm=new SimpleDateFormat("yyyy-MM-dd");
        Date settleTime = settle_time_sm.parse(param.getString("settleTime"));
        swAuCenterConductorAmountDifference.setRecordTime(settleTime);
        swAuCenterConductorAmountDifference.setConductorJobNo(param.getString("conductorJobNo"));
        swAuCenterConductorAmountDifference.setEquipmentNumber(param.getString("deviceOperateNum"));
        //swAuCenterConductorAmountDifference.setBomCode(param.getString("bomCode"));  20240808 防止合并数据，BOM编号发生变化而重复添加审核数据
        swAuCenterConductorAmountDifference.setDelFlag("0");
		//swAuCenterConductorAmountDifference.setGuardTime(settle.getGuardTime());   20240808 防止合并数据，BOM编号发生变化而重复添加审核数据
        QueryWrapper<SwAuCenterConductorAmountDifference> queryWrapper1=new QueryWrapper();
        queryWrapper1.setEntity(swAuCenterConductorAmountDifference);
        List<SwAuCenterConductorAmountDifference> swAuCenterConductorAmountDifferences = swAuCenterConductorAmountDifferenceMapper.selectList(queryWrapper1);
        boolean isExist = false;
        if(swAuCenterConductorAmountDifferences!=null && swAuCenterConductorAmountDifferences.size()>0){
            swAuCenterConductorAmountDifference=swAuCenterConductorAmountDifferences.get(0);
            isExist = true;
        }
		swAuCenterConductorAmountDifference.setBomCode(param.getString("bomCode"));
		swAuCenterConductorAmountDifference.setGuardTime(settle.getGuardTime());
        swAuCenterConductorAmountDifference.setIncomeSettleBeginTime(settleStartTime);
        swAuCenterConductorAmountDifference.setIncomeSettleEndTime(DateFormat.date_add_or_sub_days(settleEndTime,-1));//减一天
        swAuCenterConductorAmountDifference.setIncomeSettleId(settleId);
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("ifnull(group_concat(nikename),'') nikename");
        queryWrapper.in("user_code", String.valueOf(param.get("conductorJobNo")).split(","));
        List<Map<String, Object>> sysUsers = sysUserMapper.selectMaps(queryWrapper);
        String nikenames = (String) sysUsers.get(0).get("nikename");
        swAuCenterConductorAmountDifference.setConductorPersonName(nikenames);
        queryWrapper.in("user_code", String.valueOf(param.get("conductorJobNo")).split(","));
        BigDecimal paidAmount = new BigDecimal(param.getString("realAmount"));
        swAuCenterConductorAmountDifference.setPaidAmount(paidAmount);

        BigDecimal marketTicketAmount = new BigDecimal("0");
        BigDecimal passengerWorkAmount = new BigDecimal("0");
        BigDecimal singleTicketAmount = new BigDecimal("0.00");
		BigDecimal emergencyAmount = new BigDecimal("0.00");//应急纸票
        Integer haveBus = null;
		Integer haveMarket = null;
        if(param.get("isflag") == null){
            marketTicketAmount = BomUtil.getMarketTicketAmountRepair(param);//营销车票
            List<Map<String, Object>> passengerWorkAmountList = BomUtil.getPassengerWorkAmountRepair(param,settle);//乘客事务
            if(!CollectionUtils.isEmpty(passengerWorkAmountList)){
                passengerWorkAmount = (BigDecimal) passengerWorkAmountList.get(0).get("amount");
                if(passengerWorkAmount==null){
                    passengerWorkAmount = new BigDecimal("0.00");
                }
            }
            ////单程票金额
            singleTicketAmount = BomUtil.getSingleTicketAmount(param);
            //应急纸票金额
			emergencyAmount = BomUtil.getEmergencyAmount(param);
            //判断有无乘客无乘客事务
            haveBus = BomUtil.isHaveBusRepair(param,settle);
            //判断有无营销车票
			haveMarket = BomUtil.isHaveMarketRepair(param,settle);
        }else {
            marketTicketAmount = (BigDecimal) param.get("marketTicketAmount");
            passengerWorkAmount = (BigDecimal) param.get("passengerWorkAmount");
            singleTicketAmount = (BigDecimal) param.get("singleTicketAmount");
			emergencyAmount = (BigDecimal) param.get("emergencyAmount");
            haveBus = (Integer) param.get("haveBus");
			haveMarket = (Integer) param.get("haveMarket");
        }

        swAuCenterConductorAmountDifference.setMarketTicketAmount(marketTicketAmount);
        swAuCenterConductorAmountDifference.setSingleTicketAmount(singleTicketAmount);
        swAuCenterConductorAmountDifference.setPassengerWorkAmount(passengerWorkAmount);
		swAuCenterConductorAmountDifference.setEmergencyAmount(emergencyAmount);
        Map<String,Object> p=new HashMap<>();
        p.put("lineCode",param.getString("lineCode"));
        p.put("stationCode",param.getString("stationCode"));
        p.put("bomCode",param.getString("bomCode"));
        p.put("revenueTime",param.getString("settleTime"));
        p.put("startTime",DateFormat.date_ex_str(settleStartTime,"yyyyMMdd"));
        p.put("endTime",DateFormat.date_ex_str(settleEndTime,"yyyyMMdd"));
        p.put("deviceOperateNum",param.getString("deviceOperateNum"));
        swAuCenterConductorAmountDifference.setIsHaveBus(haveBus+"");
		swAuCenterConductorAmountDifference.setIsHaveMarket(haveMarket+"");
        swAuCenterConductorAmountDifference.setAuditState("0");
        //走报表差错后协查状态信息不变
        //swAuCenterConductorAmountDifference.setAssitAuditSate("0");
        swAuCenterConductorAmountDifference.setSuppState("0");
        swAuCenterConductorAmountDifference.setIsAddLayerError("0");
        swAuCenterConductorAmountDifference.setReplaceStatus("0");
        swAuCenterConductorAmountDifference.setNoticeSate("1");
        swAuCenterConductorAmountDifference.setAdditionalRecordingStatus("1");
        if(!isExist){
            swAuCenterConductorAmountDifference.setIsMergeRecord("0");//之后
        }
        swAuCenterConductorAmountDifference.setMergeConductorJobNo(param.getString("conductorJobNo"));
        swAuCenterConductorAmountDifference.setMergeConductorPersonName(nikenames);
        swAuCenterConductorAmountDifference.setMergeEquipmentNumber(param.getString("deviceOperateNum"));
        swAuCenterConductorAmountDifference.setMergeBomCode(param.getString("bomCode"));
        swAuCenterConductorAmountDifference.setIsAddReprotError("0");
        swAuCenterConductorAmountDifference.setIsAddCombinationNotice("0");
        swAuCenterConductorAmountDifference.setDataSource("2");//账面差异
        swAuCenterConductorAmountDifference.setCombinStatus("0");
        swAuCenterConductorAmountDifference.setRemark(param.getString("remark"));
        swAuCenterConductorAmountDifference.setCreatorId(UserInfo.getId());
        swAuCenterConductorAmountDifference.setCreatorName(UserInfo.getName());
        swAuCenterConductorAmountDifference.setCreateTime(new Date());
        swAuCenterConductorAmountDifference.setPassengerJobNo(param.getString("passengerAttendantJobNo"));
        swAuCenterConductorAmountDifference.setPassengerJobName(param.getString("passengerAttendantName"));
        swAuCenterConductorAmountDifference.setRepairSubmitJobNo(user.getUserCode());
        swAuCenterConductorAmountDifference.setRepairSubmitJobName(user.getNikeName());
        swAuCenterConductorAmountDifference.setRepairSubmitTime(new Date());
        BigDecimal systemAmount=new BigDecimal("0");
        if(!CollectionUtils.isEmpty(swAuCenterConductorAmountDifferences)){
            systemAmount = swAuCenterConductorAmountDifference.getSysAmount();
            systemAmount=systemAmount.divide(new BigDecimal(100));//暂时除以100，去掉四舍五入，否则数据不准确
            //0506调整为减去应急纸票减去单程票
            BigDecimal subtract = paidAmount.subtract(systemAmount).subtract(passengerWorkAmount).subtract(marketTicketAmount).subtract(singleTicketAmount).subtract(emergencyAmount);
            swAuCenterConductorAmountDifference.setDifferenceAmount(subtract.multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setPaidAmount(paidAmount.multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setMarketTicketAmount(marketTicketAmount.multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setPassengerWorkAmount((passengerWorkAmount).multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setSingleTicketAmount((singleTicketAmount).multiply(new BigDecimal(100)));
			swAuCenterConductorAmountDifference.setEmergencyAmount((emergencyAmount).multiply(new BigDecimal(100)));
			//修改售票员票款差异审核
            swAuCenterConductorAmountDifferenceMapper.updateById(swAuCenterConductorAmountDifference);
        }else{
            swAuCenterConductorAmountDifference=(SwAuCenterConductorAmountDifference)ObejctFieldsValueNotNull.jisuanBigDicmalMulti(SwAuCenterConductorAmountDifference.class,swAuCenterConductorAmountDifference,100d);
            //获取更新SC、LC、ACC三个接口数据
            swAuCenterConductorAmountDifference.setScSellAmount(scLcAcc.get("sc_sell"));
            swAuCenterConductorAmountDifference.setScInvestAmount(scLcAcc.get("sc_de"));
            swAuCenterConductorAmountDifference.setScFaretkAmount(scLcAcc.get("sc_su"));
            swAuCenterConductorAmountDifference.setLcSellAmount(scLcAcc.get("lc_sell"));
            swAuCenterConductorAmountDifference.setLcInvestAmount(scLcAcc.get("lc_de"));
            swAuCenterConductorAmountDifference.setLcFaretkAmount(scLcAcc.get("lc_su"));
            swAuCenterConductorAmountDifference.setAccSellAmount(scLcAcc.get("acc_sell"));
            swAuCenterConductorAmountDifference.setAccInvestAmount(scLcAcc.get("acc_de"));
            swAuCenterConductorAmountDifference.setAccFaretkAmount(scLcAcc.get("acc_su"));
            systemAmount=scLcAcc.get("sc_sell").add(scLcAcc.get("sc_de")).add(scLcAcc.get("sc_su"));
            BigDecimal sysAmount=systemAmount.divide(new BigDecimal(100));//暂时除以100，去掉四舍五入，否则数据不准确
            swAuCenterConductorAmountDifference.setSysAmount(systemAmount);
            BigDecimal subtract = paidAmount.subtract(sysAmount).subtract(passengerWorkAmount).subtract(marketTicketAmount).subtract(singleTicketAmount).subtract(emergencyAmount);
            swAuCenterConductorAmountDifference.setDifferenceAmount(subtract.multiply(new BigDecimal(100)));//乘以100，存到库中
            swAuCenterConductorAmountDifference.setSysDataSource("1");
            swAuCenterConductorAmountDifference.setAssitAuditSate("0");
            //保存售票员票款差异审核
            swAuCenterConductorAmountDifferenceMapper.insert(swAuCenterConductorAmountDifference);
        }
        return true;
    }


    /**
     * bom报表差错待提交
     * @param page
     * @param param
     * @return
     */
    @RequestMapping("/getXw_bom_shouJieSuan_reportError_waitSubmit")
    @ApiOperation(value = "bom报表差错待提交", notes = "bom报表差错待提交")
    public Page getXw_bom_shouJieSuan_reportError_waitSubmit(Page page,@RequestParam Map<String,String> param) throws ParseException, SQLException {

        param.put("delFlag","0");
        param.put("settleStatus","2");
        List<Map<String,Object>> resultlist=new ArrayList<>();
        //获取收入结算待提交
        List<Map<String,Object>> swStTvmIncomeSettles = swStBomIncomeSettleMapper.getXw_bom_shouJieSuan_areadySubmit(param);
        for(Map<String,Object> swStTvmIncomeSettleMap:swStTvmIncomeSettles) {
            Map<String,String> p=new HashMap<>();
            p.put("ssisId",swStTvmIncomeSettleMap.get("id")+"");
            p.put("isAddReportError","1");
            List<Map<String, Object>> tvm_shouJieSuan_waitSubmit = BomUtil.getXw_bom_shouJieSuan_waitSubmit(p);
            for (Map<String, Object> map : tvm_shouJieSuan_waitSubmit) {
                Object smtId = map.get("smtId");
                BigDecimal electronicAmount = new BigDecimal(0);//电子金额

                QueryWrapper<SwStMarketingTicketGroupSell> swStMarketingTicketGroupSellQueryWrapper = new QueryWrapper<>();
                swStMarketingTicketGroupSellQueryWrapper.select("ifnull(sum(discount_amount),0) discount_amount");
                swStMarketingTicketGroupSellQueryWrapper.eq("relation_id", smtId);
                swStMarketingTicketGroupSellQueryWrapper.eq("del_flag", 0);
                String[] pay_method = {"1", "2", "3"}; //微信，现金，银行
                swStMarketingTicketGroupSellQueryWrapper.in("pay_method", pay_method);
                List<Map<String, Object>> maps = swStMarketingTicketGroupSellMapper.selectMaps(swStMarketingTicketGroupSellQueryWrapper);//团购的
                if (maps != null && maps.size() > 0) {
                    Map<String, Object> res = maps.get(0);
                    BigDecimal discount_amount = (BigDecimal) res.get("discount_amount");
                    electronicAmount = electronicAmount.add(discount_amount);
                }
                
                QueryWrapper<SwStMarketingTicketOffineTakeTicket> swStMarketingTicketOffineTakeTicketQueryWrapper = new QueryWrapper<>();
                swStMarketingTicketOffineTakeTicketQueryWrapper.select("ifnull(sum(sell_amount),0) sell_amount");
                swStMarketingTicketOffineTakeTicketQueryWrapper.eq("relation_id", smtId);
                swStMarketingTicketOffineTakeTicketQueryWrapper.eq("del_flag", 0);
                BigDecimal sell = new BigDecimal(0);
                List<Map<String, Object>> map3 = swStMarketingTicketOffineTakeTicketMapper.selectMaps(swStMarketingTicketOffineTakeTicketQueryWrapper);//正常取得，微信，支付宝
                if (map3 != null && map3.size() > 0) {
                    Map<String, Object> res = map3.get(0);
                    BigDecimal sell_amount = (BigDecimal) res.get("sell_amount");
                    sell = sell.add(sell_amount);
                }

                electronicAmount = electronicAmount.add(sell);//add(alipayAndwechat).
                map.put("electronicAmount", electronicAmount);

                resultlist.add(map);
            }
        }
        page.setData(resultlist);
        return page;
    }

    /**
     * 已经提交的
     * @param page
     * @param param
     * @param
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getXw_bom_shouJieSuan_areadySubmit")
    @ApiOperation(value = "已经提交的", notes = "已经提交的")
    public Page getXw_tvm_shouJieSuan_areadySubmit(Page page, @RequestParam Map<String,String> param) throws ParseException {
        param.put("delFlag","0");
        //获取已提交数据
        List<Map<String,Object>> swStTvmIncomeSettles = swStBomIncomeSettleMapper.getXw_bom_shouJieSuan_areadySubmit(param);
        for(Map<String,Object> map:swStTvmIncomeSettles){
            String user_code=(String) map.get("conductorJobNo");
            user_code=user_code==null?"":user_code;
            QueryWrapper<SysUser> queryWrapper=new QueryWrapper<>();
            queryWrapper.select("ifnull(group_concat(nikename),'') conductorName");
            queryWrapper.in("user_code",user_code.split(","));
            List<Map<String, Object>> maps = sysUserMapper.selectMaps(queryWrapper);
            if(maps!=null && maps.size()>0){
                map.put("conductorName",maps.get(0).get("conductorName"));
            }
        }
        page.setData(swStTvmIncomeSettles);
        return page;
    }


    /**
     * 预览数据
     * @param
     * @param param
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getXw_bom_shouJieSuan_preview")
    @ApiOperation(value = "预览数据", notes = "预览数据")
    public Result getXw_tvm_shouJieSuan_preview(@RequestParam Map<String,String> param) throws ParseException, SQLException {
        Result res=new Result(ResultDetailMsg.OK);
        try{
			String sql ="SELECT sum(a.WINDOWS_NUM-a.WINDOWS_CLOSE_NUM) num,sum((a.WINDOWS_NUM-a.WINDOWS_CLOSE_NUM)*a.TICKET_VALUE) amount "+
						" from sw_st_ticket_petty_add_details  a,sw_st_ticket_petty_add b "+
						" where a.relation_id=b.id "+
						" and a.del_flag='0' "+
						" and b.del_flag='0' "+
						" and a.type='2' "+
						" and b.confirm_status='1' "+
						" and b.line_code='"+param.get("lineCode")+"' "+
						" and b.station_code='"+param.get("stationCode")+"' "+
						" and b.ns_job_no='"+param.get("conductorJobNo")+"'"+   //用设备操作号和班次获取对应的售票信息 有问题  售票员工号需要加上
						" and b.ns_shift='"+param.get("conductorShifts")+"'"+
						" and b.device_operate_num='"+param.get("deviceOperatorNum")+"'"+						
						" and (CASE WHEN HOUR(b.WORKING_END_TIME)<2 then DATE_FORMAT(date_sub(b.WORKING_END_TIME,INTERVAL 2 hour),'%Y-%m-%d') else DATE_FORMAT(b.WORKING_END_TIME,'%Y-%m-%d') end)='"+param.get("recordTime")+"'";
            List<Map<String, Object>> ticket_amount_maps = JdbcUtil.exeSqlQuery(sql);
		    JSONObject amount=new JSONObject();
		   if(ticket_amount_maps!=null && ticket_amount_maps.size()>0){
			   amount.put("yuFashouTicketNum",ticket_amount_maps.get(0).get("num"));
               amount.put("yuFashouTicketAmount",ticket_amount_maps.get(0).get("amount"));
			}else{
			    amount.put("yuFashouTicketNum",0);
                amount.put("yuFashouTicketAmount",0);
			}
          
            res.setData(amount);			
           
        }catch (Exception e){
            log.error("{}",e);
            res.setResult(ResultDetailMsg.CHECK_SELECT_ERROR);
        }
        return res;
    }

    /**
     * tvm长周期结算
     * @param
     * @param param
     * @param
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getXw_tvm_long_js")
    @ApiOperation(value = "tvm长周期结算", notes = "tvm长周期结算")
    public Result getXw_tvm_long_js(@RequestParam Map<String,String> param) throws ParseException {
        Result res=new Result(ResultDetailMsg.OK);
        //tvm长周期
        List<SwAuTvmBoxAmountDifference> swAuTvmBoxAmountDifferences = xwShouJieSuanMapper.getXw_tvm_long_js(param);
        res.setData(swAuTvmBoxAmountDifferences);
        return res;
    }


    /**
     * bom正式提交
     * @param json
     * @return
     */
    @RequestMapping("/bomSubmitTvmData")
    @ApiOperation(value = "bom正式提交", notes = "bom正式提交")
    @Transactional(rollbackFor = Exception.class)
//    public Result bomSubmitTvmData(@RequestParam(defaultValue = "") String params,@RequestParam String ids,String attendancePersonJobNo,@RequestParam(defaultValue = "false") Boolean isLong,String startTime,String endTime,@RequestParam(defaultValue = "false") Boolean isReport) throws ParseException, SQLException {
    public Result bomSubmitTvmData(@RequestBody JSONObject json) {
        Result res=new Result(ResultDetailMsg.OK);
        String params=json.getString("params");
        String md5 = MD5.create().digestHex(params);
        if (noPass(SecurityUtils.getUser().getId(), "bomSubmit", md5)) {
            res.setMsg("请勿重复提交");
            return res;
        }
//        String ids=json.getString("ids");
        String attendancePersonJobNo=json.getString("attendancePersonJobNo");
        Boolean isLong=json.getBoolean("isLong"); isLong=isLong==null?false:isLong;
        String startTime=json.getString("startTime");
        String endTime=json.getString("endTime");
        Boolean isReport=json.getBoolean("isReport");isReport=isReport==null?false:isReport;
		Boolean isTaskAutoSubmit=json.getBoolean("isTaskAutoSubmit");isTaskAutoSubmit=isTaskAutoSubmit==null?false:isTaskAutoSubmit;

        JSONArray jsonArray = JSONArray.parseArray(params);
        try {
            for(int i=0;i<jsonArray.size();i++){
                log.info("正式提交开始：循环01"+ LocalDateTime.now());
                JSONObject param = jsonArray.getJSONObject(i);
                if(isReport){ //报表的
                    Date endTimeD=DateFormat.panDuanDate(param.getString("settleEndTime"));
                    //利用Calendar 实现 Date日期+1天
                    Calendar c = Calendar.getInstance();
                    c.setTime(endTimeD);
                    c.add(Calendar.DAY_OF_MONTH, 1);
                    endTimeD = c.getTime();
                    param.put("startTime", DateFormat.panDuanDate(param.getString("settleStartTime")));
                    param.put("endTime",endTimeD);
                    param.put("isReport",isReport);
                }else{//待提交的
                    Date js_startSettleDate = DateFormat.panDuanDate(param.getString("js_startSettleDate"));
                    Date js_endSettleDate = DateFormat.panDuanDate(param.getString("js_endSettleDate"));
                    if(js_startSettleDate.compareTo(js_endSettleDate) == 1){
                        js_startSettleDate = DateFormat.date_add_or_sub_days(js_startSettleDate, -1);
                        param.put("js_startSettleDate",DateFormat.date_ex_str(js_startSettleDate));
                    }
                    param.put("startTime",js_startSettleDate);
                    param.put("endTime",js_endSettleDate);
                    Date startDate = DateFormat.panDuanDate(startTime);
                    Date endDate = DateFormat.panDuanDate(endTime);
                    if(isLong){
                        param.put("startTime",startDate);//yyyy-MM-dd 02:00:00
                        param.put("endTime",endDate);//推一天yyyy-MM-dd 01:59:59
                    }
                    Integer id = param.getInteger("id");
                    //查未提交的数据
                    SwStConductorSettle conductorSettle = null;
                    SwStConductorSettle settle = swStConductorSettleRepairMapper.selectById(id);//未提交数据
                    log.info("正式提交结束：循环01"+ LocalDateTime.now());
                    if(ObjectUtil.isNotEmpty(settle)){
                        //正常提交合并处理
                        log.info("正式提交开始：循环02"+ LocalDateTime.now());
                        List<SwStConductorSettle> merge = findMerge(settle);//先把已提交到审核表和结算表的数据删除掉
                        log.info("正式提交结束：循环02"+ LocalDateTime.now());
                        //重新组织数据
                        if(CollectionUtil.isNotEmpty(merge)){
                            //TODO 调用车站合并方法 原来已经提交的结算单ID和待提交的售票员结算单合并
                            List<Integer> ids = new ArrayList<>();
                            ids.add(merge.get(0).getId());//已提交id
                            ids.add(settle.getId());//未提交id

                            String paramStar = JSONObject.toJSONString(param);
                            //合并数据  对两条数据进行合并  审核补提交合并调用
                            log.info("正式提交合并数据开始：循环03"+ LocalDateTime.now());
                            R<Map<String,String>> mapR = subwayStmService.submissionMerge(settle, paramStar, ids, merge.get(0).getConductorShifts(), true, false, SecurityConstants.FROM);
                            log.info("正式提交合并数据结束：循环03"+ LocalDateTime.now());
                            int rCode = mapR.getCode();
                            if(1 == rCode) {
                                throw new RuntimeException("fegin调用异常！");
                            }
                            Map<String, String> data = mapR.getData();
                            if(data != null && !data.isEmpty()){
                                conductorSettle = JSONObject.parseObject(data.get("merge"), SwStConductorSettle.class);
                                conductorSettle.setElectronicAmount(merge.get(0).getElectronicAmount());

                                param = (JSONObject) JSONObject.toJSON(conductorSettle);
                                param.put("marketTicketAmount",new BigDecimal(data.get("marketTicketAmount")));
                                param.put("passengerWorkAmount",new BigDecimal(data.get("passengerWorkAmount")));
                                param.put("singleTicketAmount",new BigDecimal(data.get("singleTicketAmount")));
								param.put("emergencyAmount",new BigDecimal(data.get("emergencyAmount")));
                                param.put("haveBus",Integer.valueOf(data.get("haveBus")));
                                param.put("isflag","标识");

                                param.put("startTime",js_startSettleDate);
                                param.put("endTime",js_endSettleDate);
                                if(isLong){
                                    param.put("startTime",startDate);
                                    param.put("endTime",endDate);
                                }
                                param.put("passengerAttendantJobName",String.valueOf(param.get("passengerAttendantName")));
                            }
                        }
                    }

                }

                SimpleDateFormat sm2 = new SimpleDateFormat("yyyy-MM-dd");
                Date settleTime = sm2.parse(param.getString("settleTime"));

                SwStBomIncomeSettle swStBomIncomeSettle = new SwStBomIncomeSettle();
                swStBomIncomeSettle.setLineCode(param.getString("lineCode"));
                swStBomIncomeSettle.setStationCode(param.getString("stationCode"));
                swStBomIncomeSettle.setBomCode(param.getString("bomCode"));
                swStBomIncomeSettle.setConductorJobNo(param.getString("conductorJobNo"));
                swStBomIncomeSettle.setDeviceOperatorNum(param.getString("deviceOperateNum"));
                swStBomIncomeSettle.setRecordTime(settleTime);
                swStBomIncomeSettle.setConductorShifts(param.getString("conductorShifts"));//班次
                swStBomIncomeSettle.setDelFlag("0");
                QueryWrapper<SwStBomIncomeSettle> queryWrapperSwStBomIncomeSettle=new QueryWrapper<>();
                queryWrapperSwStBomIncomeSettle.setEntity(swStBomIncomeSettle);
                log.info("正式提交开始：循环04"+ LocalDateTime.now());
                List<SwStBomIncomeSettle> swStBomIncomeSettles = swStBomIncomeSettleMapper.selectList(queryWrapperSwStBomIncomeSettle);
                log.info("正式提交结束：循环04"+ LocalDateTime.now());
                if(swStBomIncomeSettles.size()>0){
                    swStBomIncomeSettle=swStBomIncomeSettles.get(0);
                }

                QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
                queryWrapper.select("ifnull(group_concat(user_id),'') user_id");
				String conductorJobNo = (String)param.get("conductorJobNo");
				if(conductorJobNo!=null && conductorJobNo!=""){
				    queryWrapper.in("user_code",conductorJobNo.split(",")); 
				}

                //queryWrapper.in("user_code", param.get("conductorJobNo"));
                log.info("正式提交开始：循环05"+ LocalDateTime.now());
                List<Map<String, Object>> sysUsers = sysUserMapper.selectMaps(queryWrapper);
                log.info("正式提交结束：循环05"+ LocalDateTime.now());
                String ConductorIds = (String) sysUsers.get(0).get("user_id");
                swStBomIncomeSettle.setConductorId(ConductorIds);

                Date workingStartTime = (Date) param.get("startTime");
                swStBomIncomeSettle.setSettleStartTime(workingStartTime);//2021-09-19

                Date workingEndTime =  (Date) param.get("endTime");//2021-09-19
                if(isReport) { //报表的
                    swStBomIncomeSettle.setSettleStartTime(settleTime);//2021-12-02
                    swStBomIncomeSettle.setSettleEndTime(settleTime);//2021-12-02 调整结束日期 防止累加  workingEndTime
                }else{
                    swStBomIncomeSettle.setSettleEndTime(DateFormat.date_add_or_sub_days(workingEndTime,-1));
                }
                Date curr_date = new Date();
                String startdateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 00:00:00";
                String middledateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 01:59:59";
                //String enddateStr=DateFormat.date_ex_str(curr_date,"yyyy-MM-dd")+" 23:59:59";

                Date startdate=DateFormat.panDuanDate(startdateStr);
                Date middledate=DateFormat.panDuanDate(middledateStr);
                //Date enddate=DateFormat.panDuanDate(enddateStr);
                Date enddate = DateFormat.date_add_or_sub_days(startdate, 1);//避免1秒误差，改为 加一天

                if(curr_date.compareTo(startdate)>=0 && curr_date.compareTo(middledate)<=0){
                    curr_date=DateFormat.date_add_or_sub_days(curr_date,-1);//前推一天
                    swStBomIncomeSettle.setSettleTime(curr_date);
                }else if(curr_date.compareTo(middledate)>0 && curr_date.compareTo(enddate)<0){
                    swStBomIncomeSettle.setSettleTime(curr_date);
                }

                swStBomIncomeSettle.setCashReceiptAmount(new BigDecimal(param.getString("realAmount")));
                swStBomIncomeSettle.setAdvanceAmount(new BigDecimal(param.getString("adanceAmount")));
                swStBomIncomeSettle.setElectronicAmount(new BigDecimal(param.getString("electronicAmount")));
				swStBomIncomeSettle.setPassengerAttendantId(1);
                swStBomIncomeSettle.setPassengerAttendantJobNo(String.valueOf(param.getString("passengerAttendantJobNo")));
                swStBomIncomeSettle.setPassengerAttendantName(String.valueOf(param.getString("passengerAttendantJobName")));
				if(!isTaskAutoSubmit){
				   Map<String, Object> p = new HashMap<>();
					 p.put("user_code", attendancePersonJobNo);
					List<SysUser> sysUsers2 = sysUserMapper.selectByMap(p);
                    swStBomIncomeSettle.setAttendancePersonId(sysUsers2.get(0).getUserId());
                    swStBomIncomeSettle.setAttendancePersonJobNo(attendancePersonJobNo);
                    swStBomIncomeSettle.setAttendancePersonName(sysUsers2.get(0).getNikename());
				}else{
				    swStBomIncomeSettle.setAttendancePersonId(1);
                    swStBomIncomeSettle.setAttendancePersonJobNo(String.valueOf(param.getString("passengerAttendantJobNo")));
                    swStBomIncomeSettle.setAttendancePersonName(String.valueOf(param.getString("passengerAttendantJobName")));
				}          

                

                long l = (workingEndTime.getTime() - workingStartTime.getTime()) / (24 * 60 * 60 * 1000);
                swStBomIncomeSettle.setSettleDays(Integer.parseInt(String.valueOf(l)));
                if(!isTaskAutoSubmit){
					swStBomIncomeSettle.setDeptId(UserInfo.getDeptId());
					swStBomIncomeSettle.setCreatorId(UserInfo.getId());
					swStBomIncomeSettle.setCreatorName(UserInfo.getName());
				}else{
				    swStBomIncomeSettle.setDeptId(1);
					swStBomIncomeSettle.setCreatorId(1);
					swStBomIncomeSettle.setCreatorName("管理员");
				}
                swStBomIncomeSettle.setCreateTime(new Date());
                swStBomIncomeSettle.setUpdateTime(new Date());
                swStBomIncomeSettle.setSettleStatus("1");
                swStBomIncomeSettle.setIsAddReportError("0");
                swStBomIncomeSettle.setDelFlag("0");
                swStBomIncomeSettle.setAdditionalRecordingStatus("0");

                log.info("正式提交开始：循环06"+ LocalDateTime.now());
                //存在更新 不存在新增
                if(swStBomIncomeSettles.size()>0){
                    swStBomIncomeSettleMapper.updateById(swStBomIncomeSettle);
                }else{
                    Integer ref = swStBomIncomeSettleMapper.insertSwStBomIncomeSettle(swStBomIncomeSettle);
                }
               // log.info("正式提交结束：循环06"+ LocalDateTime.now());
                //长周期结算
                //log.info("正式提交长周期结算开始：循环07"+ LocalDateTime.now());
                writeLongPERIOD_SETTLE_LOG(param,isTaskAutoSubmit);
                //log.info("正式提交长周期结算结束：循环07"+ LocalDateTime.now());
                //修改提交状态和报表修改状态
                //log.info("正式提交修改提交状态和报表修改状态开始：循环08"+ LocalDateTime.now());
                updateStatusSubmitStatus(param);
                //log.info("正式提交修改提交状态和报表修改状态结束：循环08"+ LocalDateTime.now());
                //修改报表差错更改申请状态
                //log.info("正式提交修改报表差错更改申请状态开始：循环09"+ LocalDateTime.now());
                updateReportDatas(param);
                //log.info("正式提交修改报表差错更改申请状态结束：循环09"+ LocalDateTime.now());
                //添加或更新售票员票款差异审核
                //log.info("正式提交添加或更新售票员票款差异审核开始：循环10"+ LocalDateTime.now());
                insertSwAuCenterConductorAmountDifference(param,swStBomIncomeSettle.getId(), isReport);
                log.info("正式提交添加或更新售票员票款差异审核开始：循环10"+ LocalDateTime.now());
                //TODO 不适用了
//                if(isReport){
//                    TvmUtil.updateReportAlert("车站售票员结算单",param.getString("settleTime"));// 后期改为将报表修改状态置为关闭
//                }
            }
        }catch (Exception e){
            log.error("提交失败",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.setMsg("提交失败");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
      return res;
    }

    /**
     * 长周期结算
     * @param param
     * @return
     */
    public boolean writeLongPERIOD_SETTLE_LOG(JSONObject param,boolean isTaskAutoSubmit){
        try {
			String paramConductorJobNo = param.getString("conductorJobNo");
			if(paramConductorJobNo ==null || "".equals(paramConductorJobNo)){
			  return false;
			}

			
			String[] conductorJobNos = paramConductorJobNo.split(",");
			/*
			if(conductorJobNos!=null && conductorJobNos.length==1){
			      conductorJobNos = new String[1];
                  conductorJobNos[0] = conductorJobNos[0];
				 
			}else if(conductorJobNos!=null && conductorJobNos.length==2){
			      String conductorJobNo1 = conductorJobNos[0];
				  String conductorJobNo2=  conductorJobNos[1];
				  if(conductorJobNo1.equals(conductorJobNo2)){
				     conductorJobNos = new String[1];
                     conductorJobNos[0] = conductorJobNos[0]; //如果是同一个售票员进行合并，只存一条记录
				  }
			}*/
			if(conductorJobNos!=null && conductorJobNos.length>0){
			     for(int i=0;i<conductorJobNos.length;i++){//考虑合并的售票员信息
				    String conductorJobNo = conductorJobNos[i];
					
				    SwStLongperiodSettleLog swStLongperiodSettleLog=new SwStLongperiodSettleLog();
					swStLongperiodSettleLog.setLineCode(param.getString("lineCode"));
					swStLongperiodSettleLog.setStationCode(param.getString("stationCode"));
					swStLongperiodSettleLog.setDeviceNo(param.getString("bomCode"));//是否需要根据BOM编号来查询判断？？？？？？？？？待定
					swStLongperiodSettleLog.setDeviceType("2");
					swStLongperiodSettleLog.setConductorJobNo(conductorJobNo);
					QueryWrapper<SwStLongperiodSettleLog> queryWrapper=new QueryWrapper<>();
					queryWrapper.setEntity(swStLongperiodSettleLog);
					List<SwStLongperiodSettleLog> swStLongperiodSettleLogs = swStLongperiodSettleLogMapper.selectList(queryWrapper);
					if(swStLongperiodSettleLogs.size()>0){
						swStLongperiodSettleLog=swStLongperiodSettleLogs.get(0);
					}

					Date settleStartTime = (Date) param.get("startTime");
					Date settleEndTime = (Date) param.get("endTime");

					swStLongperiodSettleLog.setBeginSettleDate(settleStartTime);
					swStLongperiodSettleLog.setEndSettleDate(settleEndTime);
					swStLongperiodSettleLog.setSettleDate(new Date());
					long l = (settleEndTime.getTime() - settleStartTime.getTime()) / (24 * 60 * 60 * 1000);
					swStLongperiodSettleLog.setSettlePeriod(Integer.parseInt(l+""));
					if(!isTaskAutoSubmit){
						swStLongperiodSettleLog.setSettlePersonId(UserInfo.getId());
						swStLongperiodSettleLog.setSettlePerson(UserInfo.getUserName());
						swStLongperiodSettleLog.setSettlePersonJobNo(UserInfo.getUserCode());
						swStLongperiodSettleLog.setCreatorId(UserInfo.getId());               
						swStLongperiodSettleLog.setCreatorName(UserInfo.getUserName());
					}else{
						swStLongperiodSettleLog.setSettlePersonId(1);
						swStLongperiodSettleLog.setSettlePerson("管理员");
						swStLongperiodSettleLog.setSettlePersonJobNo("001");
						swStLongperiodSettleLog.setCreatorId(1);               
						swStLongperiodSettleLog.setCreatorName("管理员");
					}
				   
					swStLongperiodSettleLog.setCreateTime(new Date());
					swStLongperiodSettleLog.setUpdateTime(new Date());

					//存在更新，不存在新增  长周期结算日志跟踪表
					if(swStLongperiodSettleLogs.size()>0){
						swStLongperiodSettleLogMapper.updateById(swStLongperiodSettleLog);
					}else{
						int ref=swStLongperiodSettleLogMapper.insertSwStLongperiodSettleLog(swStLongperiodSettleLog);
					}

				}
			}

          
        }catch (Exception e){
            log.error("{}",e);
            return false;
        }
        return true;
    }

    /**
     * 添加或更新售票员票款差异审核
     * @param param
     * @param settleId
     * @param isReport
     * @return
     * @throws ParseException
     * @throws SQLException
     * @throws IllegalAccessException
     */
    public boolean insertSwAuCenterConductorAmountDifference(JSONObject param,Integer settleId,Boolean isReport) throws ParseException, SQLException, IllegalAccessException {
        Date settleStartTime = (Date) param.get("startTime");
        Date settleEndTime = (Date) param.get("endTime");

        SwAuCenterConductorAmountDifference swAuCenterConductorAmountDifference=new SwAuCenterConductorAmountDifference();
        swAuCenterConductorAmountDifference.setLineCode(param.getString("lineCode"));
        swAuCenterConductorAmountDifference.setStationCode(param.getString("stationCode"));
        SimpleDateFormat settle_time_sm=new SimpleDateFormat("yyyy-MM-dd");
        Date settleTime = settle_time_sm.parse(param.getString("settleTime"));
        swAuCenterConductorAmountDifference.setRecordTime(settleTime);
        swAuCenterConductorAmountDifference.setConductorJobNo(param.getString("conductorJobNo"));
        swAuCenterConductorAmountDifference.setEquipmentNumber(param.getString("deviceOperateNum"));
        //swAuCenterConductorAmountDifference.setBomCode(param.getString("bomCode"));  20240808 查询是否存在去掉BOM编号
        swAuCenterConductorAmountDifference.setDelFlag("0");
        QueryWrapper<SwAuCenterConductorAmountDifference> queryWrapper1=new QueryWrapper();
        queryWrapper1.setEntity(swAuCenterConductorAmountDifference);

		//log.info("0809测试合并-------------售票员工号---"+param.getString("conductorJobNo")+"     BOM编号---- "+param.getString("bomCode")+"---设备操作好----"+param.getString("deviceOperateNum"));
        List<SwAuCenterConductorAmountDifference> swAuCenterConductorAmountDifferences = swAuCenterConductorAmountDifferenceMapper.selectList(queryWrapper1);
		//上述查询条件不能在此前面再增加其他属性，否则影响合并结算  20240808  线路  车站 收入日期 售票员工号  设备操作号确定唯一记录
		boolean isExist = false;
        if(swAuCenterConductorAmountDifferences!=null && swAuCenterConductorAmountDifferences.size()>0){
            swAuCenterConductorAmountDifference=swAuCenterConductorAmountDifferences.get(0);
			isExist = true;
        }
        swAuCenterConductorAmountDifference.setBomCode(param.getString("bomCode"));//查询后再设置该编号 20240808
        swAuCenterConductorAmountDifference.setIncomeSettleBeginTime(settleStartTime);

		//查找售票员结算单  2024-07-04 add
		SwStConductorSettle settleGuard = swStConductorSettleRepairMapper.selectById(Integer.parseInt(String.valueOf(param.get("id"))));
		swAuCenterConductorAmountDifference.setGuardTime(settleGuard.getGuardTime());

        if(isReport){
            swAuCenterConductorAmountDifference.setIncomeSettleEndTime(settleTime);//2021-12-02 调整结算日期 防止累加  settleEndTime
        }else {
            swAuCenterConductorAmountDifference.setIncomeSettleEndTime(DateFormat.date_add_or_sub_days(settleEndTime,-1));//减一天
        }
        swAuCenterConductorAmountDifference.setIncomeSettleId(settleId);

        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("ifnull(group_concat(nikename),'') nikename");
//        queryWrapper.in("user_code", param.get("handlePersonCode"));
        queryWrapper.in("user_code", String.valueOf(param.get("conductorJobNo")).split(","));
        List<Map<String, Object>> sysUsers = sysUserMapper.selectMaps(queryWrapper);
        String nikenames = (String) sysUsers.get(0).get("nikename");
        swAuCenterConductorAmountDifference.setConductorPersonName(nikenames);

//        BigDecimal paidAmount = BomUtil.getPaidAmount(param);
        BigDecimal paidAmount = new BigDecimal(param.getString("realAmount"));
        swAuCenterConductorAmountDifference.setPaidAmount(paidAmount);

        BigDecimal marketTicketAmount = new BigDecimal("0");
        BigDecimal passengerWorkAmount = new BigDecimal("0");
        BigDecimal singleTicketAmount = new BigDecimal("0.00");
		BigDecimal emergencyAmount = new BigDecimal("0.00");
		
        Integer haveBus = null;
		Integer haveMarket = null;
        if(param.get("isflag") == null){
            //获取营销车票金额
            marketTicketAmount = BomUtil.getMarketTicketAmount(param);
            List<Map<String, Object>> passengerWorkAmountList = BomUtil.getPassengerWorkAmount(param);//乘客事务
            if(!CollectionUtils.isEmpty(passengerWorkAmountList)){
                passengerWorkAmount = (BigDecimal) passengerWorkAmountList.get(0).get("amount");
                if(passengerWorkAmount==null){
                    passengerWorkAmount = new BigDecimal("0.00");
                }
            }
            //获取单程票金额
            singleTicketAmount = BomUtil.getSingleTicketAmount(param);
            //获取应急纸票金额
			emergencyAmount = BomUtil.getEmergencyAmount(param);
			//判断是否有无乘客事务
            haveBus = BomUtil.isHaveBus(param);
            //判断是否有无营销车票
			haveMarket = BomUtil.isHaveMarket(param);
        }else {
            marketTicketAmount = (BigDecimal) param.get("marketTicketAmount");
            passengerWorkAmount = (BigDecimal) param.get("passengerWorkAmount");
            singleTicketAmount = (BigDecimal) param.get("singleTicketAmount");
			emergencyAmount = 	(BigDecimal)param.get("emergencyAmount");
            haveBus = (Integer) param.get("haveBus");
			haveMarket = (Integer) param.get("haveMarket");
        }
        swAuCenterConductorAmountDifference.setMarketTicketAmount(marketTicketAmount);
        swAuCenterConductorAmountDifference.setSingleTicketAmount(singleTicketAmount);
		swAuCenterConductorAmountDifference.setEmergencyAmount(emergencyAmount);
		swAuCenterConductorAmountDifference.setPassengerWorkAmount(passengerWorkAmount);

        //swAuCenterConductorAmountDifference.setAuditTime(settleTime); 审核日期不设置

        /*swAuCenterConductorAmountDifference.setSysDataSource("1");
        swAuCenterConductorAmountDifference.setDataSource("2");*/

        Map<String,Object> p=new HashMap<>();
        p.put("lineCode",param.getString("lineCode"));
        p.put("stationCode",param.getString("stationCode"));
        p.put("bomCode",param.getString("bomCode"));
        p.put("revenueTime",param.getString("settleTime"));
        p.put("startTime",DateFormat.date_ex_str(settleStartTime,"yyyyMMdd"));
        p.put("endTime",DateFormat.date_ex_str(settleEndTime,"yyyyMMdd"));
        p.put("deviceOperateNum",param.getString("deviceOperateNum"));


//        swAuCenterConductorAmountDifference.setScSellAmount(new BigDecimal(0));
//        swAuCenterConductorAmountDifference.setScSellAmount(new BigDecimal(0));


        swAuCenterConductorAmountDifference.setIsHaveBus(haveBus+"");
		swAuCenterConductorAmountDifference.setIsHaveMarket(haveMarket+"");
        swAuCenterConductorAmountDifference.setAuditState("0");
        //swAuCenterConductorAmountDifference.setAssitAuditSate("0");
        swAuCenterConductorAmountDifference.setSuppState("0");
        swAuCenterConductorAmountDifference.setIsAddLayerError("0");
        swAuCenterConductorAmountDifference.setReplaceStatus("0");
        swAuCenterConductorAmountDifference.setNoticeSate("1");
//        swAuCenterConductorAmountDifference.setIsMergeRecord(String.valueOf(param.getString("handlePersonCode").contains(",")?1:0));
        //swAuCenterConductorAmountDifference.setIsMergeRecord(String.valueOf(param.getString("conductorJobNo").contains(",")?1:0));
		if(!isExist){
		   swAuCenterConductorAmountDifference.setIsMergeRecord("0");//之后
		}
		
//        swAuCenterConductorAmountDifference.setMergeConductorJobNo(param.getString("handlePersonCode"));
        swAuCenterConductorAmountDifference.setMergeConductorJobNo(param.getString("conductorJobNo"));
        swAuCenterConductorAmountDifference.setMergeConductorPersonName(nikenames);
        swAuCenterConductorAmountDifference.setMergeEquipmentNumber(param.getString("deviceOperateNum"));
        swAuCenterConductorAmountDifference.setMergeBomCode(param.getString("bomCode"));
        swAuCenterConductorAmountDifference.setIsAddReprotError("0");
        swAuCenterConductorAmountDifference.setIsAddCombinationNotice("0");
        swAuCenterConductorAmountDifference.setDataSource("2");//账面差异
        swAuCenterConductorAmountDifference.setCombinStatus("0");
        swAuCenterConductorAmountDifference.setRemark(param.getString("remark"));		
        swAuCenterConductorAmountDifference.setCreatorId(UserInfo.getId());
        swAuCenterConductorAmountDifference.setCreatorName(UserInfo.getName());
        swAuCenterConductorAmountDifference.setCreateTime(new Date());

        if(isReport){
            swAuCenterConductorAmountDifference.setUpdateJobNo(UserInfo.getUserCode());
            swAuCenterConductorAmountDifference.setUpdateJobName(UserInfo.getName());
            swAuCenterConductorAmountDifference.setUpdateTime(new Date());
			swAuCenterConductorAmountDifference.setDataSource("1");//调账差异
        }else{
            
            //swAuCenterConductorAmountDifference.setPassengerJobNo(UserInfo.getUserCode());
            //swAuCenterConductorAmountDifference.setPassengerJobName(UserInfo.getName());
			swAuCenterConductorAmountDifference.setPassengerJobNo(param.getString("passengerAttendantJobNo"));
            swAuCenterConductorAmountDifference.setPassengerJobName(param.getString("passengerAttendantJobName"));
        }


        if(swAuCenterConductorAmountDifferences.size()>0){
           /* Map<String, BigDecimal> scLcAcc = BomUtil.getScLcAcc(p);
            swAuCenterConductorAmountDifference.setScInvestAmount(scLcAcc.get("sc_de"));
            swAuCenterConductorAmountDifference.setScSellAmount(scLcAcc.get("sc_sell"));
            swAuCenterConductorAmountDifference.setScFaretkAmount(scLcAcc.get("sc_return"));

            swAuCenterConductorAmountDifference.setLcInvestAmount(scLcAcc.get("lc_de"));
            swAuCenterConductorAmountDifference.setLcSellAmount(scLcAcc.get("lc_sell"));
            swAuCenterConductorAmountDifference.setLcFaretkAmount(scLcAcc.get("lc_return"));

            swAuCenterConductorAmountDifference.setAccInvestAmount(scLcAcc.get("acc_de"));
            swAuCenterConductorAmountDifference.setAccSellAmount(scLcAcc.get("acc_sell"));
            swAuCenterConductorAmountDifference.setAccFaretkAmount(scLcAcc.get("acc_return"));*/
            BigDecimal systemAmount = swAuCenterConductorAmountDifference.getSysAmount();
            systemAmount=systemAmount.divide(new BigDecimal(100));//暂时除以100
			//0506调整为减去应急纸票减去单程票
            BigDecimal subtract = paidAmount.subtract(systemAmount).subtract(passengerWorkAmount).subtract(marketTicketAmount).subtract(singleTicketAmount).subtract(emergencyAmount);
            swAuCenterConductorAmountDifference.setDifferenceAmount(subtract.multiply(new BigDecimal(100)));

            swAuCenterConductorAmountDifference.setPaidAmount(paidAmount.multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setMarketTicketAmount(marketTicketAmount.multiply(new BigDecimal(100)));			
			swAuCenterConductorAmountDifference.setEmergencyAmount(emergencyAmount.multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setPassengerWorkAmount((passengerWorkAmount).multiply(new BigDecimal(100)));
            swAuCenterConductorAmountDifference.setSingleTicketAmount((singleTicketAmount).multiply(new BigDecimal(100)));
//1000 -0-0-129=871
            swAuCenterConductorAmountDifferenceMapper.updateById(swAuCenterConductorAmountDifference);
        }else{
            swAuCenterConductorAmountDifference=(SwAuCenterConductorAmountDifference)ObejctFieldsValueNotNull.jisuanBigDicmalMulti(SwAuCenterConductorAmountDifference.class,swAuCenterConductorAmountDifference,100d);
            BigDecimal systemAmount=new BigDecimal(0);
			
            swAuCenterConductorAmountDifference.setSysAmount(systemAmount);
			 BigDecimal subtract = paidAmount.subtract(systemAmount).subtract(passengerWorkAmount).subtract(marketTicketAmount).subtract(singleTicketAmount).subtract(emergencyAmount);
			//2021-03-13  
            swAuCenterConductorAmountDifference.setDifferenceAmount(subtract.multiply(new BigDecimal(100)));//乘以100，存到库中
            swAuCenterConductorAmountDifference.setSysDataSource("1");
            swAuCenterConductorAmountDifference.setAssitAuditSate("0");

            swAuCenterConductorAmountDifferenceMapper.insert(swAuCenterConductorAmountDifference);
        }
        return true;
    }

    /**
     * 修改提交状态和报表修改状态
     * @param js
     * @return
     * @throws SQLException
     */
    private boolean updateStatusSubmitStatus(JSONObject js) throws SQLException {
        try {
//            Date startTimeD = js.getDate("startTime");
//            Date endTimeD = js.getDate("endTime");
            SimpleDateFormat settle_time_sm=new SimpleDateFormat("yyyy-MM-dd");
            Date settleTime = settle_time_sm.parse(js.getString("settleTime"));
            Date endSettleTime = settleTime;

            //利用Calendar 实现 Date日期+1天
            Calendar c = Calendar.getInstance();
            c.setTime(endSettleTime);
            c.add(Calendar.DAY_OF_MONTH, 1);
            endSettleTime = c.getTime();

            //只满足配备用金和配票 endDate+1天
            String startTime=DateFormat.date_ex_str(settleTime,"yyyy-MM-dd")+" 02:00:00";
            String endTime=DateFormat.date_ex_str(endSettleTime,"yyyy-MM-dd")+" 01:59:59";

            String startDate=DateFormat.date_ex_str(settleTime,"yyyy-MM-dd");
            String endDate=DateFormat.date_ex_str(settleTime,"yyyy-MM-dd");

			String lineCode=js.getString("lineCode");
			String stationCode = js.getString("stationCode");
            String bomCode = js.getString("bomCode");
			String conductorJobNo = js.getString("conductorJobNo");
			String deviceOperatorNum = js.getString("deviceOperateNum");
			String conductorShifts = js.getString("conductorShifts");
            Map<String, String> map = new HashMap<>();
            map.put("lineCode",lineCode);
            map.put("stationCode",stationCode);
            map.put("conductorJobNo",conductorJobNo);
            map.put("deviceOperatorNum",deviceOperatorNum);
            map.put("conductorShifts",conductorShifts);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            map.put("startDate",startDate);
            map.put("endDate",endDate);
            //售票员结算表
            try {
                swStConductorSettleRepairMapper.update(null,Wrappers.<SwStConductorSettle>lambdaUpdate()
                        .setSql("approval_status='1',REPORT_MODIFY_STATUS='0'")
                        .eq(SwStConductorSettle::getId,js.getString("id"))
                );
                log.info("updateStatusSubmitStatus售票员结算表:"+lineCode+"--"+stationCode+"--"+conductorJobNo+"--"+deviceOperatorNum+"--"+conductorShifts+"--"+startTime+"--"+endTime+"--"+startDate+"--"+endDate);
            } catch (Exception e) {
                throw new RuntimeException("售票员结算表异常",e);
            }
            //车站配票与配备用金
            try {
                swStTicketPettyAddMapper.edit(map);
                //swStTicketPettyAddMapper.update(null,Wrappers.<SwStTicketPettyAdd>lambdaUpdate()
                //        //.setSql("submit_status='1',REPORT_MODIFY_STATUS='0'")
                //        .set(SwStTicketPettyAdd::getSubmitStatus,"1")
                //        .set(SwStTicketPettyAdd::getReportModifyStatus,"0")
                //        .eq(SwStTicketPettyAdd::getLineCode,lineCode)
                //        .eq(SwStTicketPettyAdd::getStationCode,stationCode)
                //        .eq(SwStTicketPettyAdd::getNsJobNo,conductorJobNo)
                //        .eq(SwStTicketPettyAdd::getDeviceOperateNum,deviceOperatorNum)
                //        .eq(SwStTicketPettyAdd::getDelFlag,"0")
                //        .eq(SwStTicketPettyAdd::getNsShift,conductorShifts)
                //        .eq(SwStTicketPettyAdd::getConfirmStatus,"1")
                //        .between(SwStTicketPettyAdd::getWorkingEndTime,startTime,endTime)
                //);
                log.info("updateStatusSubmitStatus车站配票与配备用金");
            } catch (Exception e) {
                throw new RuntimeException("车站配票与配备用金异常",e);
            }
            //乘客事务录入主表审核
            try {
                swStInputPassengerWorkMapper.update(null,Wrappers.<SwStInputPassengerWork>lambdaUpdate()
                        //.setSql("submit_status='1',REPORT_MODIFY_STATUS='0'")
                        .set(SwStInputPassengerWork::getSubmitStatus,"1")
                        .set(SwStInputPassengerWork::getReportModifyStatus,"0")
                        .eq(SwStInputPassengerWork::getLineCode,lineCode)
                        .eq(SwStInputPassengerWork::getStationCode,stationCode)
                        .eq(SwStInputPassengerWork::getConductorCode,conductorJobNo)
                        .eq(SwStInputPassengerWork::getDeviceOperateNum,deviceOperatorNum)
						.eq(SwStInputPassengerWork::getBomCode,bomCode)
                        .eq(SwStInputPassengerWork::getDelFlag,"0")
                        .eq(SwStInputPassengerWork::getClassNumber,conductorShifts)
                        .eq(SwStInputPassengerWork::getConfirmStatus,"1")
                        .between(SwStInputPassengerWork::getWorkDate,startDate,endDate)
                );
                log.info("updateStatusSubmitStatus乘客事务录入主表审核");
            } catch (Exception e) {
                throw new RuntimeException("乘客事务录入主表审核异常",e);
            }
            //乘客事务退换票
            try {
                swStInputPassengerWorkTicketMapper.update(null,Wrappers.<SwStInputPassengerWorkTicket>lambdaUpdate()
                        //.setSql("submit_status='1',REPORT_MODIFY_STATUS='0'")
                        .set(SwStInputPassengerWorkTicket::getSubmitStatus,"1")
                        .set(SwStInputPassengerWorkTicket::getReportModifyStatus,"0")
                        .eq(SwStInputPassengerWorkTicket::getLineCode,lineCode)
                        .eq(SwStInputPassengerWorkTicket::getStationCode,stationCode)
                        .eq(SwStInputPassengerWorkTicket::getHandlePersonCode,conductorJobNo)
                        .eq(SwStInputPassengerWorkTicket::getDeviceOperateNum,deviceOperatorNum)
                        .eq(SwStInputPassengerWorkTicket::getDelFlag,"0")
                        .eq(SwStInputPassengerWorkTicket::getClassNumber,conductorShifts)
                        .eq(SwStInputPassengerWorkTicket::getConfirmStatus,"1")
                        .apply("DATE_FORMAT(handle_time,'%Y-%m-%d') between '"+startDate+"' and '"+endDate+"'")
                );
                log.info("updateStatusSubmitStatus乘客事务退换票");
            } catch (Exception e) {
                throw new RuntimeException("乘客事务退换票异常",e);
            }

            //营销车票审核主表
            try {
                swStMarketingTicketMapper.update(null,Wrappers.<SwStMarketingTicket>lambdaUpdate()
                        //.setSql("approval_status='1',REPORT_MODIFY_STATUS='0'")
                        .set(SwStMarketingTicket::getApprovalStatus,"1")
                        .set(SwStMarketingTicket::getReportModifyStatus,"0")
                        .eq(SwStMarketingTicket::getLineCode,lineCode)
                        .eq(SwStMarketingTicket::getStationCode,stationCode)
                        .eq(SwStMarketingTicket::getConductorJobNo,conductorJobNo)
                        .eq(SwStMarketingTicket::getDeviceOperateNum,deviceOperatorNum)
                        .eq(SwStMarketingTicket::getBomCode,bomCode)
                        .eq(SwStMarketingTicket::getDelFlag,"0")
                        .eq(SwStMarketingTicket::getConductorShifts,conductorShifts)
                        .eq(SwStMarketingTicket::getConfirmStatus,"1")
                        .between(SwStMarketingTicket::getOpertorTime,startDate,endDate)
                );
                log.info("updateStatusSubmitStatus营销车票审核主表");
            } catch (Exception e) {
                throw new RuntimeException("营销车票审核主表异常",e);
            }
            //其他相关数据录入
            try {
                swStInputPassengerWorkOtherMapper.update(null,Wrappers.<SwStInputPassengerWorkOther>lambdaUpdate()
                        //.setSql("submit_status='1',REPORT_MODIFY_STATUS='0'")
                        .set(SwStInputPassengerWorkOther::getSubmitStatus,"1")
                        .set(SwStInputPassengerWorkOther::getReportModifyStatus,"0")
                        .eq(SwStInputPassengerWorkOther::getLineCode,lineCode)
                        .eq(SwStInputPassengerWorkOther::getStationCode,stationCode)
                        .eq(SwStInputPassengerWorkOther::getConductorCode,conductorJobNo)
                        .eq(SwStInputPassengerWorkOther::getDeviceOperateNum,deviceOperatorNum)
                        .eq(SwStInputPassengerWorkOther::getDelFlag,"0")
                        .eq(SwStInputPassengerWorkOther::getClassNumber,conductorShifts)
                        .eq(SwStInputPassengerWorkOther::getConfirmStatus,"1")
                        .apply("DATE_FORMAT(input_time,'%Y-%m-%d') between '"+startDate+"' and '"+endDate+"'")
                );
                log.info("updateStatusSubmitStatus其他相关数据录入");
            } catch (Exception e) {
                throw new RuntimeException("其他相关数据录入异常",e);
            }
            //xwShouJieSuanMapper.updatePetty(lineCode,stationCode,startTime,endTime,conductorJobNo,deviceOperatorNum,conductorShifts);
            //JdbcUtil.exeSqlCrud("update sw_st_conductor_settle set approval_status='1',REPORT_MODIFY_STATUS='0'  where id="+js.getString("id"));
            //JdbcUtil.exeSqlCrud("update sw_st_ticket_petty_add set submit_status='1',REPORT_MODIFY_STATUS='0'  where LINE_CODE='"+lineCode+"' and STATION_CODE='"+stationCode+"' and working_end_time between '"+startTime+"' and '"+endTime+"' and NS_JOB_NO='"+conductorJobNo+"' and DEVICE_OPERATE_NUM='"+deviceOperatorNum+"' and NS_SHIFT='"+conductorShifts+"' and del_flag = '0' and CONFIRM_STATUS = '1' ");
            //JdbcUtil.exeSqlCrud("update sw_st_input_passenger_work set submit_status='1',REPORT_MODIFY_STATUS='0' where line_code='"+lineCode+"' and station_code='"+stationCode + "' and work_date between '"+startDate+"' and '"+endDate+"' and CONDUCTOR_CODE='"+conductorJobNo+"' and DEVICE_OPERATE_NUM='"+deviceOperatorNum+"' and CLASS_NUMBER='"+conductorShifts+"' and del_flag = '0' and CONFIRM_STATUS = '1'");
            //JdbcUtil.exeSqlCrud("update sw_st_input_passenger_work_ticket set submit_status='1',REPORT_MODIFY_STATUS='0' where line_code='"+lineCode+"' and station_code='"+stationCode+"' and date_format(handle_time,'%Y-%m-%d') between '"+startDate+"' and '"+endDate+"' and  HANDLE_PERSON_CODE='"+conductorJobNo+"' and DEVICE_OPERATE_NUM='"+deviceOperatorNum+"' and CLASS_NUMBER='"+conductorShifts+"' and del_flag = '0' and CONFIRM_STATUS = '1'");
            //JdbcUtil.exeSqlCrud("update sw_st_input_passenger_work_other set submit_status='1',REPORT_MODIFY_STATUS='0' where line_code='"+lineCode+"' and station_code='"+stationCode+"' and date_format(input_time,'%Y-%m-%d') between '"+startDate+"' and '"+endDate+"' and  CONDUCTOR_CODE='"+conductorJobNo+"' and DEVICE_OPERATE_NUM='"+deviceOperatorNum+"' and CLASS_NUMBER='"+conductorShifts+"' and del_flag = '0' and CONFIRM_STATUS = '1'");
            //JdbcUtil.exeSqlCrud("update sw_st_marketing_ticket set approval_status='1',REPORT_MODIFY_STATUS='0' where line_code='"+lineCode+"' and station_code='"+stationCode+"' and opertor_time between '"+startDate+"' and '"+endDate+"'  and CONDUCTOR_JOB_NO='"+conductorJobNo+"' and DEVICE_OPERATE_NUM='"+deviceOperatorNum+"' and CONDUCTOR_SHIFTS='"+conductorShifts+"' and del_flag = '0' and CONFIRM_STATUS = '1'");

        }catch (Exception e) {
            log.error("{}",e);
            return false;
        }
        return true;
    }

    /**
     * 修改报表差错更改申请状态
     * @param js
     * @return
     */
    private boolean updateReportDatas(JSONObject js){
        //获取报表差错更改申请表
        List<Map<String,Object>> reportList =  swStReportErrorAlterAppayMapper.getReportErrorForUpdate(js);
        for (Map<String, Object> stringObjectMap : reportList) {
            Object id = stringObjectMap.get("id");
            QueryWrapper<SwStReportErrorAlterApply> wrapper = new QueryWrapper<>();
            wrapper.lambda().eq(SwStReportErrorAlterApply::getId,id);
            SwStReportErrorAlterApply swStReportErrorAlterApply = new SwStReportErrorAlterApply();
            swStReportErrorAlterApply.setIsModify("1");
            swStReportErrorAlterApply.setModifyTime(new Date());
            swStReportErrorAlterAppayMapper.update(swStReportErrorAlterApply,wrapper);
        }
        return true;
    }

    /**
     * 查询是否有待确认数据
     * @param param
     * @return
     * @throws SQLException
     */
    @RequestMapping("/getBomNotConfirmDatas")
    @ApiOperation(value = "查询是否有待确认数据", notes = "查询是否有待确认数据")
    public Result getBomNotConfirmDatas(@RequestParam Map<String,Object> param) throws SQLException {
        Result res=new Result(ResultDetailMsg.OK);
        try {
            //弹框提示使用  查询是否有待确认数据
            JSONObject bomNotConfirmData = BomUtil.getBomNotConfirmData(param);
            res.setData(bomNotConfirmData);
        }catch (Exception e){
            log.error("{}",e);
            res.setResult(ResultDetailMsg.CHECK_SELECT_ERROR);
            res.setMsg("查询出错");
        }
        return res;
    }

    /**
     * 查询是否有待确认数据
     * @param param
     * @return
     * @throws SQLException
     */
    @RequestMapping("/getReportBomNotConfirmDatas")
    @ApiOperation(value = "查询是否有待确认数据", notes = "查询是否有待确认数据")
    public Result getReportBomNotConfirmDatas(@RequestParam Map<String,String> param) throws SQLException {
        Result result=new Result(ResultDetailMsg.OK);
        try {
            //收入结算待提交
            List<Map<String, Object>> xw_bom_shouJieSuan_areadySubmit = swStBomIncomeSettleMapper.getXw_bom_shouJieSuan_areadySubmit(param);

            Integer beiYongJins=0;
            Integer yingXioaChePiaos=0;
            Integer cksws=0;
            Integer spyrjs=0;
            Integer qtxgsj=0;
            Integer ckswthp=0;
            for(Map<String, Object> map:xw_bom_shouJieSuan_areadySubmit){
                Map<String,Object> p=new HashMap<>();
                p.put("lineCode",map.get("lineCode"));
                p.put("stationCode",map.get("stationCode"));
                p.put("startSettleDate",DateFormat.ex_strDate_to_date(String.valueOf(map.get("settleStartTime")),"yyyy-MM-dd"));
                p.put("endSettleDate",DateFormat.ex_strDate_to_date(String.valueOf(map.get("settleEndTime")),"yyyy-MM-dd"));
                JSONObject bomNotConfirmData = BomUtil.getBomNotConfirmData(p);
                beiYongJins+=bomNotConfirmData.getInteger("beiYongJins");
                yingXioaChePiaos+=bomNotConfirmData.getInteger("yingXioaChePiaos");
                cksws+=bomNotConfirmData.getInteger("cksws");
                qtxgsj+=bomNotConfirmData.getInteger("qtxgsj");
                ckswthp+=bomNotConfirmData.getInteger("ckswthp");
                spyrjs+=bomNotConfirmData.getInteger("spyrjs");
            }

            JSONObject res=new JSONObject();
            res.put("beiYongJins",beiYongJins);
            res.put("yingXioaChePiaos",yingXioaChePiaos);
            res.put("cksws",cksws);
            res.put("qtxgsj",qtxgsj);
            res.put("ckswthp",ckswthp);
            res.put("spyrjs",spyrjs);

            result.setData(res);
        }catch (Exception e){
            log.error("{}",e);
            result.setResult(ResultDetailMsg.CHECK_SELECT_ERROR);
            result.setMsg("查询出错");
        }
        return result;
    }

    @Override
    public RedisTemplate<String, String> redisTemplate() {
        return redisTemplate;
    }
}
